<?php
namespace frontend\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;

use frontend\config\routeParams;
use common\helpers\PublicFun;
use common\collection\Common;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }
    // 首页
    public function actionIndex()
    {
        $JsonData = Yii::$app->request->post();
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('FCustomerCaseGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = json_decode($result['Body'],true);
        return $this->render('index',array('ret' => $result));
    }
    // 集客
    public function actionCollectgust()
    {
        return $this->render('collectgust');
    }
    // 客户管理
    public function actionGustmange()
    {
        return $this->render('gustmange');
    }
    // 行业方案
    public function actionProject()
    {
        return $this->render('project');
    }
    //商家社区
    public function actionCommunity()
    {
        return $this->render('community');
    }
    //咨询合作
    public function actionCooperation()
    {
        return $this->render('cooperation');
    }

    //下载
    public function actionDownload()
    {
        return $this->render('download');
    }

    //登录
    public function actionLogin()
    {
        return $this->render('login');
    }

    //联系我们
    public function actionContactus()
    {
        return $this->render('contactus');
    }
    //产品建议
    public function actionSuggest()
    {
        return $this->render('suggest');
    }
    // 找回密码
    public function actionForget()
    {
        return $this->render('forget');
    }
    // 关于我们
    public function actionAbout()
    {
        return $this->render('about');
    }
    

    //登录
    public function actionLoginin(){
        $callback = Yii::$app->request->get('callback');
        //JsonData接收Resquest的参数
        $JsonData = Yii::$app->request->post('data');
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['AuthId'] = Common::CreateGuid();
        //经过所有的验证 调用登录接口获取用户信息
        $url = routeParams::HttpUrl('AdminLogin');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        if($result['IsBizSuccess']){  //登记登录成功
            // 从"response"组件中获取cookie 集合(yii\web\CookieCollection)
            $cookies = Yii::$app->response->cookies;
            // 在要发送的响应中添加一个新的cookie
            $cookies->add(new \yii\web\Cookie([
                'name' => 'MytipIdBack',
                'value' => $result['MytipInfo']['MytipId'],
                'expire'=>time()+60*60*24*30,
            ]));
            Yii::$app->response->send();
            //die();
            echo $callback . "(" . json_encode($result) . ")";exit;
        }else{
            echo $callback . "(" . json_encode($result) . ")";exit;
        }
    }

    // 图形验证
    public function actionCheckCode(){
        session_start();
        $callback = Yii::$app->request->get('callback');
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $vcode = $JsonData['vcode'];
        //图片验证码
        // print_r($vcode);exit;
        $sessionvcode = $_SESSION['vcode'];
        if(strtoupper($sessionvcode)!=strtoupper($vcode)){
            $info = [
                'status' => 0,
                'ErrMsg' => '验证码不正确！',
            ];
        }else{
            $info = [
                'status' => 1,
                'ErrMsg' => '填写正确！',
            ];
        }
        echo $callback . "(" . json_encode($info) . ")";exit;
    }

    // 验证码
    public function actionYzm(){
//         $callback=isset($_GET['callback']) ? trim($_GET['callback']) : '';
//         $Phone=yii::app()->request->getParam('Phone');
//         $edit=yii::app()->request->getParam('edit');
//         if($edit){
//             $url=yii::app()->params['route']['PCGetForgotCaptcha'];   //修改密码验证码
//         }else{
//             $url=yii::app()->params['route']['PCGetCaptcha'];   //注册验证码
//         }
//         $Data=array(
//             'Phone' => $Phone
//         );
//         $result=PublicFun::PostPackage($Data,$url);
//         $result=json_decode($result['Body'],true);
// //        var_dump($url);
// //        var_dump($result);
// //        var_dump($Data);
// //        exit;
//         if($result['IsBizSuccess']){
//             $this->_end(1,$result,'',$callback);
//         }else{
//             $this->_end(0,$result['ErrMsg'],'',$callback);
//         }
//         {
           $callback = Yii::$app->request->get('callback');
           $datapost = Yii::$app->request->post();
           $datapost = Common::ArrayFilter($datapost);
           $route = 'FForgetCaptchaGet';
           $url = routeParams::HttpUrl($route);
           $result = PublicFun::PostPackage($datapost['data'], $url);
           $result = json_decode($result['Body'],true);
           // print_r($result);exit;
           echo $callback . "(" . json_encode($result) . ")";exit;
    }
    // 申请试用
    public function actionAply()
    {
        $JsonData = Yii::$app->request->post();
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('FProbationApply');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    // 客户案例
    public function actionCumgetlist()
    {
        $callback = Yii::$app->request->get('callback');
        $JsonData = Yii::$app->request->post();
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('FCustomerCaseGetList');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = json_decode($result['Body'],true);
        echo $callback . "(" . json_encode($result) . ")";
    }
    // 找回密码
    public function actionResetPassword()
    {
        $callback = Yii::$app->request->get('callback');
        $JsonData = Yii::$app->request->post();
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('FResetPassword');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = json_decode($result['Body'],true);
        echo $callback . "(" . json_encode($result) . ")";
    }
    // 提交建议
    public function actionCreatesu()
    {
        $callback = Yii::$app->request->get('callback');
        $JsonData = Yii::$app->request->post();
        $JsonData = Common::ArrayFilter($JsonData);
        $url = routeParams::HttpUrl('FProductAdviseCreate');
        $result = PublicFun::PostPackage($JsonData['data'], $url);
        $result = json_decode($result['Body'],true);
        echo $callback . "(" . json_encode($result) . ")";
    }
    
    
  

}
